/**
 * @fileOverview IFrame plugin
 */
(function() {
   VED.plugins.add( 'iframe', {
      requires: 'dialog,fakeobjects',
      lang: 'ru,en', // %REMOVE_LINE_CORE%
      icons: 'iframe', // %REMOVE_LINE_CORE%
      onLoad: function() {
         VED.addCss( 'img.ved_iframe' +
            '{' +
               'background-image: url(' + VED.getUrl( this.path + 'images/placeholder.png' ) + ');' +
               'background-position: center center;' +
               'background-repeat: no-repeat;' +
               'border: 1px solid #a9a9a9;' +
               'width: 80px;' +
               'height: 80px;' +
            '}'
            );
      },
      init: function( editor ) {
         var pluginName = 'iframe',
            lang = editor.lang.iframe,
            allowed = 'iframe[align,longdesc,frameborder,height,name,scrolling,src,title,width]';

         if ( editor.plugins.dialogadvtab )
            allowed += ';iframe' + editor.plugins.dialogadvtab.allowedContent( { id:1,classes:1,styles:1 } );

         VED.dialog.add( pluginName, this.path + 'dialogs/iframe.js' );
         editor.addCommand( pluginName, new VED.dialogCommand( pluginName, {
            allowedContent: allowed,
            requiredContent: 'iframe'
         } ) );

         editor.ui.addButton && editor.ui.addButton( 'Iframe', {
            label: lang.toolbar,
            command: pluginName,
            toolbar: 'insert,80'
         });

         editor.on( 'doubleclick', function( evt ) {
            var element = evt.data.element;
            if ( element.is( 'img' ) && element.data( 'ved-real-element-type' ) == 'iframe' )
               evt.data.dialog = 'iframe';
         });

         if ( editor.addMenuItems ) {
            editor.addMenuItems({
               iframe: {
                  label: lang.title,
                  command: 'iframe',
                  group: 'image'
               }
            });
         }

         // If the "contextmenu" plugin is loaded, register the listeners.
         if ( editor.contextMenu ) {
            editor.contextMenu.addListener( function( element, selection ) {
               if ( element && element.is( 'img' ) && element.data( 'ved-real-element-type' ) == 'iframe' )
                  return { iframe: VED.TRISTATE_OFF };
            });
         }
      },
      afterInit: function( editor ) {
         var dataProcessor = editor.dataProcessor,
            dataFilter = dataProcessor && dataProcessor.dataFilter;

         if ( dataFilter ) {
            dataFilter.addRules({
               elements: {
                  iframe: function( element ) {
                     return editor.createFakeParserElement( element, 'ved_iframe', 'iframe', true );
                  }
               }
            });
         }
      }
   });
})();
